<?php
class M_validasi extends Nvl_Model{
	function __construct(){
		parent::__construct();
		$this->table_name='m_validasi';
		$this->column_primary='validasi_id';
		$this->column_order='';
		$this->column_unique='validasi_name';
		$this->column_active='validasi_aktif';
	}
	
	function get_list($start, $pagesize, $search_text){
		$this->db->select("
			prestasi_id,
			lomba_judul,
			lomba_cp,
			juara_nama,
			prestasi_valid
		");
		if($search_text != ''){
			$this->db->like('lomba_judul', $search_text);
		}
		if($pagesize != 0){
			$this->db->limit($pagesize, $start);
		}
		if($_SESSION[SESSION_SCHOOLID] != 0){
			$this->db->where('prestasi_sekolah_id', $_SESSION[SESSION_SCHOOLID]);
		}
		
		$this->db->join('t_lomba', 't_lomba.lomba_id = t_prestasi.prestasi_lomba_id');
		$this->db->join('m_juara', 'm_juara.juara_id = t_prestasi.prestasi_juara_id');
		$this->db->where('prestasi_valid IS NULL OR prestasi_valid = 0');
		$record = $this->db->get('t_prestasi');
		$final[] = array(
			"total"=>$record->num_rows(),
			"results"=>$record->result()
		);
		return json_encode($final);
	}
	function get_list_detail($prestasi_id){
		$this->db->select("
			det_prestasi_id,
			det_prestasi_siswa_id AS siswa_nis,
			det_prestasi_siswa_nama AS siswa_nama,
			det_prestasi_siswa_alamat AS siswa_alamat,
			det_prestasi_siswa_kelas AS siswa_kelas,
			det_prestasi_siswa_tgllahir AS siswa_tgllahir
		");
		
		$this->db->where('det_prestasi_prestasi_id', $prestasi_id);
		$record = $this->db->get('t_prestasi_det');
		$final[] = array(
			"total"=>$record->num_rows(),
			"results"=>$record->result()
		);
		return json_encode($final);
	}
}